<span page-title ng-model="filter">{{ 'Repositories for Filter:' | translate }} {{ filter.name }}</span>

<div class="row">
  <div class="col-sm-8">
    <div class="radio">
      <label>
        <input type="radio"
               ng-value="false"
               ng-model="showRepos"
               ng-hide="denied('edit_content_views', contentView)"
               ng-click="selectAllRepositories()"/>
        <span translate>This filter applies to all repositories in the content view (current and future).</span>
      </label>
    </div>
    <div class="radio">
      <label>
        <input type="radio"
               ng-value="true"
               ng-hide="denied('edit_content_views', contentView)"
               ng-model="showRepos"/>
        <span translate>This filter applies only to a subset of repositories in the content view.</span>
      </label>
    </div>
  </div>
</div>

<div ng-class="{'table-mask': !showRepos}">
  <div data-extend-template="layouts/partials/table.html">
    <div data-block="list-actions">
      <button type="button" class="btn btn-default"
              translate
              ng-hide="denied('edit_content_views', contentView)"
              ng-disabled="!showRepos || table.numSelected === 0"
              ng-click="updateRepositories()">
        Update Repositories
      </button>
    </div>

    <div data-block="search">
      <div class="input-group">
        <span class="input-group-addon">
          <select ng-model="product" ng-options="product.name for (id, product) in products"></select>
        </span>

        <input type="text"
               class="form-control"
               placeholder="{{ 'Filter' | translate }}"
               ng-model="repositorySearch"/>
      </div>
    </div>

    <div data-block="table">
      <table bst-table="table"
             class="table table-striped table-bordered"
             ng-class="{'table-mask': table.working}">
        <thead>
          <tr bst-table-head row-select>
            <th bst-table-column="name" translate>Name</th>
            <th bst-table-column="product" translate>Product</th>
            <th bst-table-column="type" translate>Type</th>
            <th bst-table-column="sync-status" translate>Sync Status</th>
            <th bst-table-column="content" translate>Content</th>
          </tr>
        </thead>

        <tbody>
          <tr bst-table-row
              row-select="repository"
              ng-hide="denied('edit_content_views', contentView)"
              ng-disabled="!showRepos"
              ng-repeat="repository in table.rows | filter:repositorySearch | filter:repositoryFilter">
            <td bst-table-cell>
              <a ui-sref="product.repository.info({productId: repository.product.id, repositoryId: repository.id})">
                {{ repository.name }}
              </a>
            </td>
            <td bst-table-cell>
              <a ui-sref="product.info({productId: repository.product.id})">
                {{ repository.product.name }}
              </a>
            </td>
            <td bst-table-cell>{{ repository.content_type }}</td>
            <td bst-table-cell>
                <span ng-show="repository.url">
                  <span ng-show="repository.last_sync == null" translate>
                    Not Synced
                  </span>
                  <span ng-hide="repository.last_sync == null">
                    <a href="/foreman_tasks/tasks/{{repository.last_sync.id}}">{{ repository.last_sync.result | capitalize}}</a>
                    <short-date-time date="repository.last_sync.ended_at" />
                  </span>
                </span>
              <span ng-hide="repository.url" translate>N/A</span>
            </td>
            <td bst-table-cell>
              <div ng-if="repository.content_counts.rpm && repository.content_counts.rpm > 0">
                <a ui-sref="product.repository.manage-content.packages({productId: repository.product.id, repositoryId: repository.id})"
                   ng-show="repository.content_type == 'yum'"
                   translate>
                  {{ repository.content_counts.rpm }} Packages
                </a>
              </div>
              <div ng-if="repository.content_counts.erratum && repository.content_counts.erratum > 0">
                <a ui-sref="errata({repositoryId: repository.id})"
                   ng-show="repository.content_type == 'yum'"
                   translate>
                  {{ repository.content_counts.erratum }} Errata
                </a>
              </div>
              <div ng-if="repository.content_counts.module_stream && repository.content_counts.module_stream > 0">
                <a ui-sref="product.repository.manage-content.module-streams({productId: repository.product.id, repositoryId: repository.id})" translate>
                  {{ repository.content_counts.module_stream || 0 }} Module Streams
                </a>
              </div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</div>
